# @Author   : tan90
# @Time     : 2025/1/24 17:58
from openai import OpenAI

client = OpenAI(api_key="sk-a56d40b0bdb84ae9a8d27921aefc0ffe", base_url="https://api.deepseek.com")

response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[
        {"role": "system", "content": "你是Python编程高手"},
        {"role": "user", "content": "如何定义列表变量"},
    ],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.reasoning_content:
        print(chunk.choices[0].delta.reasoning_content, end="")

    elif chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

    elif chunk.usage:
        print()
        cUsage = chunk.usage
        print(
            f"{cUsage.prompt_tokens} {cUsage.completion_tokens} {cUsage.total_tokens} {cUsage.prompt_cache_hit_tokens} {cUsage.prompt_cache_miss_tokens}")
